
/*
 * ajax请求封装
 */
var s = {
    /** 服务器地址 */
    server_host: "",

    get: function (url, params, successCallback, errorCallback) {
        s.ajax('GET', url, params, successCallback, errorCallback);
    },

    post: function (url, params, successCallback, errorCallback) {
        s.ajax('POST', url, params, successCallback, errorCallback);
    },

    put: function (url, params, successCallback, errorCallback) {
        s.ajax('PUT', url, params, successCallback, errorCallback);
    },

    delete: function (url, params, successCallback, errorCallback) {
        s.ajax('DELETE', url, params, successCallback, errorCallback);
    },

    /**
     * @params requestType    请求服务器的方式
     * @params url    请求服务器url地址
     * @params requestHeader    请求头参数,json格式
     * @params paramsy    请求参数(对象)
     * @params callback        回调函数
     */
    ajax: function (method, url, params, successCallback, errorCallback) {
        if (url == null || url == "") {
            return;
        }
        var requestHeader = {

        }
        if (params == null || params == "") {
            params = {};
        }

        var settings = {
            type: method,
            url: s.server_host + url,
            dataType: "json",
            headers: requestHeader,
            data: method!='GET'?JSON.stringify(params):null,
            contentType: "application/json",
            success: function (data, textStatus) {
                if (successCallback != undefined)
                    successCallback(data, textStatus);
            },
            error: function (data) {
                console.debug(data);
            }
        };

        // 发送ajax请求
        $.ajax(settings);
    }

}
